package com.xyh.transaction.common;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum UserRole {
    Admin(1,"管理员"),
    Seller(2,"卖家"),
    Buyer(3,"买家");

    private static final Map<String, UserRole> map = new HashMap<>();

    static {
        for (UserRole role : UserRole.values()) {
            map.put(role.getDetail(), role);
        }
    }

    UserRole(Integer code, String detail){
        this.code = code;
        this.detail = detail;

    }

    private final Integer code;

    private final String detail;

    public static UserRole getByDetail(String detail) {
        UserRole role = map.get(detail);
        if (role == null) {
            // 处理未知的详情字符串，例如返回一个默认值或抛出异常
            throw new IllegalArgumentException("Unknown pay type: " + detail);
        }
        return role;
    }

}
